package map07;

import java.util.HashMap;

/**
 * 集合嵌套:集合套集合
 * ArrayList<ArrayList>
 * ArrayList<HashSet>
 * HashMap<ArrayList,HashMap>
 * Map套Map
 * 需求:
 * 一班
 * 1001 张三
 * 1002 李四
 * 1005 王五
 * 二班
 * 2003 无忌
 * 2005 乔峰
 * 2007 虚竹
 * 嵌套集合构造数据从内向外构建
 * 嵌套集合遍历从外向内遍历
 */
public class HashMapDemo01 {
    public static void main(String[] args) {
        //1.构建嵌套集合以及填充数据
        HashMap<String, String> students1 = new HashMap<>();
        students1.put("1001", "张三");
        students1.put("1002", "李四");
        students1.put("1005", "王五");

        HashMap<String, String> students2 = new HashMap<>();
        students2.put("2003", "无忌");
        students2.put("2005", "乔峰");
        students2.put("2007", "虚竹");

        //2.构建最外层的HashMap<String,HashMap<String,String>>
        HashMap<String, HashMap<String, String>> classRoom = new HashMap<>();
        classRoom.put("一班", students1);
        classRoom.put("二班", students2);

        //3.遍历嵌套集合
        for (String roomName : classRoom.keySet()) {//遍历最外层集合
            HashMap<String, String> hm = classRoom.get(roomName);//根据当前遍历的key,取出对应value,而这个value又是一个HashMap
            for (String sno : hm.keySet()) {
                System.out.println(roomName + " " + sno + " " + hm.get(sno));
            }
        }

    }
}
